package org.example.code.test2025.three_month;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class test0309 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        for (int i = 0; i < t; i++) {
            int n = in.nextInt();
            int[] arr = new int[n];
            for (int j = 0; j < n; j++) {
                arr[j] = in.nextInt();
            }
            int re = fun(arr, n);
            System.out.println(re);
        }
    }

    private static int fun2(int[] arr, int n) {
        int count = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                if (arr[i] > arr[j]) {
                    count++;
                }
            }
        }
        return count;
    }

    private static int fun(int[] arr, int n) {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if (fun3(arr, i)) {
                list.add(i);
            }
        }
        int k = list.size();
        int mod = 998244353;
        int[] arr2 = new int[k + 1];
        arr2[0] = 1;
        for (int i = 1; i <= k; i++) {
            arr2[i] = (int) ((long) arr2[i - 1] * 2 % mod);
        }
        return (arr2[k] - 2 + mod) % mod;
    }

    private static boolean fun3(int[] arr, int k) {
        int[] newArr = new int[arr.length - 1];
        int j = 0;
        for (int i = 0; i < arr.length; i++) {
            if (i != k) {
                newArr[j++] = arr[i];
            }
        }
        int o = fun2(arr, arr.length);
        int o2 = fun2(newArr, arr.length);
        return o == o2;
    }
}
